﻿using DeviceCommons.DeviceMessages.Enums;
using DeviceCommons.DeviceMessages.Models.V1;

namespace DeviceCommons.DeviceMessages.Factories
{
    public class DefaultStateFactory : IStateFactory
    {
        public IDeviceMessageInfoReadingState CreateState(byte sid, object value, StateValueTypeEnum? valueType = null)
        {
            return new DeviceMessageInfoReadingState
            {
                SID = sid,
                ValueType = valueType ?? StateValueTypeEnum.String,
                ValueText = value
            };
        }

        public IDeviceMessageInfoReadingStates CreateStates(params StateValueTypeEnum[] types)
        {
            return new DeviceMessageInfoReadingStates()
            {
                StateArray = new IDeviceMessageInfoReadingState[]
                {
                    CreateState("PLC",1,0d),
                    CreateState("PLC",2,0),
                    CreateState(3,true)
                }
            };
        }

        public IDeviceMessageInfoReadingState CreateState(string metadata, byte sid, object value, StateValueTypeEnum? valueType = null)
        {
            IDeviceMessageInfoReadingState state = CreateState(sid, value, valueType);
            state.Metadata = metadata;
            return state;
        }
    }
}
